package com.happy016.persist.base.impl;

import com.happy016.mapper.IBaseMapper;
import com.happy016.persist.base.IBaseDao;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 基础的增删改查
 * @author linyb
 * create on 2017/6/19 11:31
 */
public class BaseDaoImpl<T,K>  implements IBaseDao<T,K> {

    @Autowired
    private IBaseMapper<T> baseMapper;

    @Override
    public Integer save(T entity) {
        return baseMapper.insert(entity);
    }

    @Override
    public Integer saveSelective(T entity) {
        return baseMapper.insertSelective(entity);
    }

    @Override
    public Integer saveUseGeneratedKeys(T entity) {
        return baseMapper.insertUseGeneratedKeys(entity);
    }

    @Override
    public Integer delete(K id) {
        return baseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer deleteByEntity(T entity) {
        return baseMapper.delete(entity);
    }

    @Override
    public Integer update(T entity) {
        return baseMapper.updateByPrimaryKey(entity);
    }

    @Override
    public Integer updateSelective(T entity) {
        return baseMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public T get(K id) {
        return baseMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<T> findAll() {
        return baseMapper.selectAll();
    }

    @Override
    public List<T> findAllByEntity(T entity) {
        return baseMapper.select(entity);
    }

    @Override
    public T findOneByEntity(T entity) {
        return baseMapper.selectOne(entity);
    }

    @Override
    public Integer findCountByEntity(T entity) {
        return baseMapper.selectCount(entity);
    }

    @Override
    public List<T> findByIds(String ids) {
        return baseMapper.selectByIds(ids);
    }

    @Override
    public Integer deleteByIds(String ids) {
        return baseMapper.deleteByIds(ids);
    }

    @Override
    public Integer saveList(List<T> entitys) {
        return baseMapper.insertList(entitys);
    }

}
